package com.community.service.impl;

import com.community.mapper.AdminMapper;
import com.community.pojo.User;
import com.community.service.AdminElderlyHealthService;
import com.community.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {
    private final AdminMapper adminMapper;
    private final AdminElderlyHealthService adminElderlyHealthService;
    @Autowired
    public AdminServiceImpl(AdminMapper adminMapper, AdminElderlyHealthService adminElderlyHealthService) {
        this.adminMapper = adminMapper;
        this.adminElderlyHealthService = adminElderlyHealthService;
    }

    public int addUser(User user) {
        int n= adminMapper.addUser(user);
        return n;
    }

    public int deleteUser(Integer userId){
        adminElderlyHealthService.deleteByUserId(userId);
        int n= adminMapper.deleteUser(userId);
        return n;
    }

    public int updatePassword(Integer userId,String newPassword){
        int n= adminMapper.updatePassword(userId,newPassword);
        return n;
    }

    public int updateUser(User user){
        int n= adminMapper.updateUser(user);
        return n;
    }
    public User findUser(Integer userId){
        User user= adminMapper.findUser(userId);
        return user;
    }
    public List<User> findAllUser(){
        List<User> userList= adminMapper.findAllUser();
        return userList;
    }

    @Override
    public User findUserByUsername(String username) {
        User user= adminMapper.findUserByUsername(username);
        return user;
    }
}
